<template>
  <div style="width: 80%;margin-left: 10%">
    <div style="text-align: center;margin-bottom: 50px">
      <h1> 指标设置</h1>
    </div>
    <Divider />
    <div>
      <template>
        <Form :model="formItem" :label-width="80">
          <Row class="bench_search">
            <Col span="7" class="ivu-form-item-label">标题：</Col>
            <Col span="11" class="ivu-form-item-content">
              <Input v-model="formItem.title"></Input>
              请输入指标名称.
            </Col>
          </Row>
          <Row class="bench_search">
            <Col span="7" class="ivu-form-item-label">投诉率：</Col>
            <Col span="10" class="ivu-form-item-content">
              <Input v-model="formItem.complaint" type="number"></Input>
              请输入投诉率占比(百分比).
            </Col>
            <Col span="1" class="ivu-form-item-label">%</Col>
          </Row>
          <Row class="bench_search">
            <Col span="7" class="ivu-form-item-label">办结率：</Col>
            <Col span="10" class="ivu-form-item-content">
              <Input v-model="formItem.finish" type="number"></Input>
              请输入办结率占比(百分比).
            </Col>
            <Col span="1" class="ivu-form-item-label">%</Col>
          </Row>
          <div style="text-align: center;margin-top: 50px">
            <Button type="error" @click="submit" style="margin-right: 50px" size="large">确定</Button>
            <Button type="info" size="large" @click="fanhui">返回</Button>
          </div>
        </Form>
      </template>
    </div>
  </div>
</template>

<script>
import { saveIndexManagement, getIndexManagement } from '@/api/eventlist'
export default {
  name: 'index',
  data () {
    return {
      code: '',
      urlcode: '',
      name: '',
      formItem: {
        title: '',
        complaint: '',
        finish: ''
      },
      paramData: {
        title: '',
        complaint: '',
        finish: ''
      }
    }
  },
  mounted () {
    this.init()
  },
  methods: {
    fanhui () {
      this.$router.push({
        path: '/mainv3'
      })
    },
    submit () {
      this.paramData.complaint = this.formItem.complaint || ''
      this.paramData.finish = this.formItem.finish || ''
      this.paramData.title = this.formItem.title || ''
      console.log(100 - this.paramData.complaint - this.paramData.finish, '334455')
      if (100 - this.paramData.complaint - this.paramData.finish === 0) {
        saveIndexManagement(this.paramData).then(res => {
          console.log(res, 'qwertW')
          if (res.data.errmsg === 'success') {
            this.$Notice.success({ title: '成功', desc: '' })
            // this.searchData(this.currentPageNo
          } else {
            this.$Notice.error({ title: '失败', desc: res.data.errmsg })
          }
        })
      } else {
        this.$Notice.error({ title: '失败率加投诉率相加应为百分之百' })
      }
    },
    init () {
      getIndexManagement().then(ret => {
        if (ret.data.errcode === 0) {
          this.formItem.title = ret.data.data.title
          this.formItem.complaint = ret.data.data.complaint
          this.formItem.finish = ret.data.data.finish
        }
      })
    },
    appeal () {
      var url = 'http://sy.lnxf.gov.cn/Home/EventCenter2?currRegionId='
      this.appeaAreaList1.forEach((item, index) => {
        if (this.code === item.tittle) {
          this.urlcode = item.value
        }
      })
      window.open(url + this.urlcode)
      this.$router.push({
        path: '/mainv3'
      })
    }
  }
}
</script>

<style scoped>
  .bench_search {
    margin-bottom: 10px;
  }
</style>
